package com.example.user.user

import android.content.Context
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.alibaba.android.arouter.launcher.ARouter
import com.example.library_base.base.BaseEventHandler
import com.example.library_base.router.UserRouterPath
import com.example.user.R
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.android.qualifiers.ActivityContext
import javax.inject.Inject

@Module
@InstallIn(ActivityComponent::class)
class UserEventHandler @Inject constructor(
    @ActivityContext val mContext: Context
): BaseEventHandler() {

    fun showToast(){
        Toast.makeText(mContext, "toast显示", Toast.LENGTH_SHORT).show()

    }

    fun showDialog(){
        if (isFastClick()){
            println("点击太快")
            val dialog = AlertDialog.Builder(mContext).setTitle("标题")
                    .setMessage("弹窗消息")
                    .setNegativeButton("取消"
                    ) { dialog, _ -> dialog?.dismiss() }
                    .setPositiveButton("确定"
                    ) { dialog, _ ->
                        dialog?.dismiss()
                        Toast.makeText(mContext, "点击了确定", Toast.LENGTH_SHORT).show()
                    }
                    .create()

            dialog.show()
        }
    }

    fun skipLogin(){
        ARouter.getInstance().build(UserRouterPath.USER_LOGIN)
            .withTransition(R.anim.right_in, R.anim.left_out)
            .navigation(mContext)
    }

}